package CenterFactory;
use YAML::Tiny;
use SecurityCenter;

sub new{
	my $self = {};
	bless $self; 
	return $self;	
}

sub load_centers_from_yaml_file{
	my $self = shift;
	my $config_file = shift;
	my @array_hashref = YAML::LoadFile($config_file);
	if (!@array_hashref){
		return(undef, "The configuration file is in wrong format")
	}else{
		my $centers = [];
		foreach my $hashref (@array_hashref){
			my $tmp = SecurityCenter::new();
			$tmp->copy($hashref);		
			push @$centers, $tmp;
		}
		return $centers, "Successfully loaded"; 
	} 	
}

sub get_center_by_code{
	my $self = shift;
	my $center_code = shift;
	my $centers = shift;
	if ($center_code eq ""){return(undef,"The center code is empty")};
	foreach my $center (@$centers){
		if ($center->{CODE} eq $center_code) { 
			return ($center,"Found one center");
		}
	}
	return (undef, "No center found");
}

sub DESTROY{
	
}

1; 